<?php

/**
 * 导入类
 */
use EasyWeChat\Factory;

/**
 * 微信公众号菜单操作类
 */
class WechatOfficialMenu extends OfficialBase {

    /**
     * 获取菜单列表
     */
    public function getMenuList() {

        $menuList = $this->app->menu->list();
        return $menuList;
    }  

    /**
     * 创建菜单
     * 例：
     * $buttons = [
     *       [
     *           "type" => "click",
     *           "name" => "今日歌曲",
     *           "key"  => "V1001_TODAY_MUSIC"
     *       ],
     *       [
     *           "name"       => "菜单",
     *           "sub_button" => [
     *              [
     *                   "type" => "view",
     *                   "name" => "搜索",
     *                   "url"  => "http://www.soso.com/"
     *               ],
     *               [
     *                   "type" => "view",
     *                   "name" => "视频",
     *                   "url"  => "http://v.qq.com/"
     *               ],
     *               [
     *                   "type" => "click",
     *                   "name" => "赞一下我们",
     *                   "key" => "V1001_GOOD"
     *               ],
     *           ],
     *       ],
     *   ];
     */
    public function createMenu($buttons) {
        $this->app->create($buttons);
    }

    /**
     * 删除菜单
     * $menuId 菜单ID 
     * 如果$menuId存在 删除指定菜单 否则删除所有
     */
    public function deleteMenu($menuId = null) {
        if($menuId){
            $this->app->menu->delete($menuId);
        }else{
            $this->app->menu->delete();
        }
    }
}
